package com.apes.fa.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.scm.masterdata.frame.model.DutyCenter;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = FaCardAccount.CONST_TABLE_NAME)
public class FaCardAccount extends Model {

    public static final String CONST_TABLE_NAME = "fa_card_account";

    @Id
    @Column(name = "id", nullable = false, length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "卡片账", prefix = "KPZ%(yy)", padding = 6)
    @Comment("卡片账ID")
    private String id;

    @Column(name = "summary")
    @Comment("摘要")
    @States(name = "摘要", values = {
            @State(id = "1", name = "添加卡片"),
            @State(id = "2", name = "提取折旧"),
            @State(id = "3", name = "盘亏"),
            @State(id = "4", name = "报废"),
            @State(id = "5", name = "投资转出"),
    })
    //摘要(1:添加卡片;2:提取折旧;3:盘亏;4:报废;5:投资转出;)
    private String summary;

    @Column(name = "quantity")
    @Comment("数量")
    private Integer quantity;

    @Column(name = "original_value_increased")
    @Comment("原值增加")
    private Double originalValueIncreased;

    @Column(name = "original_value_decrease")
    @Comment("原值减少")
    private Double originalValueDecrease;

    @Column(name = "original_value_balance")
    @Comment("原值余额")
    private Double originalValueBalance;

    @Column(name = "increase_depreciation")
    @Comment("本月增加折旧")
    private Double increaseDepreciation;

    @Column(name = "reduce_depreciation")
    @Comment("本月减少折旧")
    private Double reduceDepreciation;

    @Column(name = "accumulated_depreciation")
    @Comment("累计折旧")
    private Double accumulatedDepreciation;

    @Column(name = "net_worth")
    @Comment("净值")
    private Double netWorth;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "bookkeeper_id", referencedColumnName = "id")
    @Comment("记账人")
    private PartyRole bookkeeper;

    @Column(name = "bookkeeping_date")
    @Comment("记账日期")
    private Date bookkeepingDate;

    @Column(name = "fa_card_id")
    @Comment("卡片ID")
    private String faCardId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id",nullable = false)
    @Comment("公司")
    private PartyRole company;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cost_center_id", referencedColumnName = "id",nullable = false)
    @Comment("成本中心")
    private DutyCenter costCenter;
}
